<?php
	// Trực tuyến - Phần xử lý
	class onlinedb
	{
		public function Add($sidOnline = '', $timeOut = 0)
		{
			$date	= getdate();
			$now	= $date[0];
			$sql	= "insert into online(sidOnline, timeOut) values('$sidOnline', ".dataservice::QuoteSmart($now + $timeOut).")";
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function Count()
		{
			$date	= getdate();
			$now	= $date[0];
			$sql	= "select count(*) numOnline from online where (1) and timeOut >= ".$now;
			
			$db = new dataservice();
			$ret = $db->ExecuteQuery($sql);
			return $ret;
		}
		
		public function Update($sidOnline = '', $timeOut = 0)
		{
			$date	= getdate();
			$now	= $date[0];
			$sql	= "update online set timeOut = ".($now + $timeOut)." where sidOnline = ".dataservice::QuoteSmart($sidOnline);
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function Delete()
		{
			$date	= getdate();
			$now	= $date[0];
			$sql	= "delete from online where (1) and timeOut < ".$now;
			
			$db = new dataservice();
			$ret = $db->ExecuteNonQuery($sql);
			return $ret;
		}
		
		public function Check($sidOnline = '')
		{
			$sql = "select * from online where (1) and sidOnline = ".dataservice::QuoteSmart($sidOnline);
			
			$db  = new dataservice();
			$ret = $db->ExecuteQuery($sql);
			return $ret;
		}
	}
?>